package rohyunji;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.JTextField;

import java.awt.BorderLayout;
import java.awt.CardLayout;
import java.awt.FlowLayout;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class CreateCompany extends JPanel {
	CompanyVO cv=new CompanyVO();
	CompanyDAO cdao=new CompanyDAO();
	private String mb_no;
	/**
	 * Create the 
	 */
	public CreateCompany(String mb_number,final CardLayout menu2AreaCard, final JPanel menuArea2,final CardLayout rightCard, final JPanel right_area) {
		
		setLayout(new BorderLayout(0, 0));
		mb_no=mb_number;

		System.out.println(mb_no);
		JPanel panel_4 = new JPanel();
		add(panel_4);
		GridBagLayout gbl_panel_4 = new GridBagLayout();
		gbl_panel_4.columnWidths = new int[]{0, 0, 350, 0, 0};
		gbl_panel_4.rowHeights = new int[]{0, 0, 0, 0, 0, 0, 0, 0, 36, 0, 0, 0, 0};
		gbl_panel_4.columnWeights = new double[]{0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE};
		gbl_panel_4.rowWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, Double.MIN_VALUE};
		panel_4.setLayout(gbl_panel_4);
		
		JLabel lblid = new JLabel("기업회원ID");
		GridBagConstraints gbc_lblid = new GridBagConstraints();
		gbc_lblid.anchor = GridBagConstraints.EAST;
		gbc_lblid.insets = new Insets(0, 0, 5, 5);
		gbc_lblid.gridx = 1;
		gbc_lblid.gridy = 1;
		panel_4.add(lblid, gbc_lblid);
		
		
		final JLabel lblNewLabel = new JLabel("d");
		lblNewLabel.setText("");
		
		GridBagConstraints gbc_lblNewLabel = new GridBagConstraints();
		gbc_lblNewLabel.insets = new Insets(0, 0, 5, 5);
		gbc_lblNewLabel.anchor = GridBagConstraints.WEST;
		gbc_lblNewLabel.gridx = 2;
		gbc_lblNewLabel.gridy = 1;
		panel_4.add(lblNewLabel, gbc_lblNewLabel);
		
		JLabel lblNewLabel_4 = new JLabel("사업자번호 ");
		GridBagConstraints gbc_lblNewLabel_4 = new GridBagConstraints();
		gbc_lblNewLabel_4.insets = new Insets(0, 0, 5, 5);
		gbc_lblNewLabel_4.anchor = GridBagConstraints.EAST;
		gbc_lblNewLabel_4.gridx = 1;
		gbc_lblNewLabel_4.gridy = 2;
		panel_4.add(lblNewLabel_4, gbc_lblNewLabel_4);
		
		final JTextField cp_reg_no = new JTextField();
		GridBagConstraints gbc_cp_reg_no = new GridBagConstraints();
		gbc_cp_reg_no.insets = new Insets(0, 0, 5, 5);
		gbc_cp_reg_no.fill = GridBagConstraints.HORIZONTAL;
		gbc_cp_reg_no.gridx = 2;
		gbc_cp_reg_no.gridy = 2;
		panel_4.add(cp_reg_no, gbc_cp_reg_no);
		cp_reg_no.setColumns(10);
		
		JLabel lblNewLabel_1 = new JLabel("( - 빼고 입력 )");
		GridBagConstraints gbc_lblNewLabel_1 = new GridBagConstraints();
		gbc_lblNewLabel_1.insets = new Insets(0, 0, 5, 0);
		gbc_lblNewLabel_1.gridx = 3;
		gbc_lblNewLabel_1.gridy = 2;
		panel_4.add(lblNewLabel_1, gbc_lblNewLabel_1);
		
		JLabel lblNewLabel_3 = new JLabel("기업명 ");
		GridBagConstraints gbc_lblNewLabel_3 = new GridBagConstraints();
		gbc_lblNewLabel_3.anchor = GridBagConstraints.EAST;
		gbc_lblNewLabel_3.insets = new Insets(0, 0, 5, 5);
		gbc_lblNewLabel_3.gridx = 1;
		gbc_lblNewLabel_3.gridy = 3;
		panel_4.add(lblNewLabel_3, gbc_lblNewLabel_3);
		
		final JTextField cp_name = new JTextField();
		GridBagConstraints gbc_cp_name = new GridBagConstraints();
		gbc_cp_name.insets = new Insets(0, 0, 5, 5);
		gbc_cp_name.fill = GridBagConstraints.HORIZONTAL;
		gbc_cp_name.gridx = 2;
		gbc_cp_name.gridy = 3;
		panel_4.add(cp_name, gbc_cp_name);
		cp_name.setColumns(10);
		
		JLabel lblNewLabel_2 = new JLabel("대표자명 ");
		GridBagConstraints gbc_lblNewLabel_2 = new GridBagConstraints();
		gbc_lblNewLabel_2.anchor = GridBagConstraints.EAST;
		gbc_lblNewLabel_2.insets = new Insets(0, 0, 5, 5);
		gbc_lblNewLabel_2.gridx = 1;
		gbc_lblNewLabel_2.gridy = 4;
		panel_4.add(lblNewLabel_2, gbc_lblNewLabel_2);
		
		final JTextField cp_pre = new JTextField();
		GridBagConstraints gbc_cp_pre = new GridBagConstraints();
		gbc_cp_pre.insets = new Insets(0, 0, 5, 5);
		gbc_cp_pre.fill = GridBagConstraints.HORIZONTAL;
		gbc_cp_pre.gridx = 2;
		gbc_cp_pre.gridy = 4;
		panel_4.add(cp_pre, gbc_cp_pre);
		cp_pre.setColumns(10);
		
		JLabel lblNewLabel_5 = new JLabel("기업주소 ");
		GridBagConstraints gbc_lblNewLabel_5 = new GridBagConstraints();
		gbc_lblNewLabel_5.anchor = GridBagConstraints.EAST;
		gbc_lblNewLabel_5.insets = new Insets(0, 0, 5, 5);
		gbc_lblNewLabel_5.gridx = 1;
		gbc_lblNewLabel_5.gridy = 5;
		panel_4.add(lblNewLabel_5, gbc_lblNewLabel_5);
		
		final JTextField cp_addr = new JTextField();
		GridBagConstraints gbc_cp_addr = new GridBagConstraints();
		gbc_cp_addr.insets = new Insets(0, 0, 5, 5);
		gbc_cp_addr.fill = GridBagConstraints.HORIZONTAL;
		gbc_cp_addr.gridx = 2;
		gbc_cp_addr.gridy = 5;
		panel_4.add(cp_addr, gbc_cp_addr);
		cp_addr.setColumns(10);
		
		JLabel lblNewLabel_6 = new JLabel("기업연락처");
		GridBagConstraints gbc_lblNewLabel_6 = new GridBagConstraints();
		gbc_lblNewLabel_6.anchor = GridBagConstraints.EAST;
		gbc_lblNewLabel_6.insets = new Insets(0, 0, 5, 5);
		gbc_lblNewLabel_6.gridx = 1;
		gbc_lblNewLabel_6.gridy = 6;
		panel_4.add(lblNewLabel_6, gbc_lblNewLabel_6);
		
		final JTextField cp_phone = new JTextField();
		GridBagConstraints gbc_cp_phone = new GridBagConstraints();
		gbc_cp_phone.insets = new Insets(0, 0, 5, 5);
		gbc_cp_phone.fill = GridBagConstraints.HORIZONTAL;
		gbc_cp_phone.gridx = 2;
		gbc_cp_phone.gridy = 6;
		panel_4.add(cp_phone, gbc_cp_phone);
		cp_phone.setColumns(10);
		
		JLabel lblNewLabel_7 = new JLabel("업종");
		GridBagConstraints gbc_lblNewLabel_7 = new GridBagConstraints();
		gbc_lblNewLabel_7.anchor = GridBagConstraints.EAST;
		gbc_lblNewLabel_7.insets = new Insets(0, 0, 5, 5);
		gbc_lblNewLabel_7.gridx = 1;
		gbc_lblNewLabel_7.gridy = 7;
		panel_4.add(lblNewLabel_7, gbc_lblNewLabel_7);
		
		final JTextField cp_job_type = new JTextField();
		GridBagConstraints gbc_cp_job_type = new GridBagConstraints();
		gbc_cp_job_type.insets = new Insets(0, 0, 5, 5);
		gbc_cp_job_type.fill = GridBagConstraints.HORIZONTAL;
		gbc_cp_job_type.gridx = 2;
		gbc_cp_job_type.gridy = 7;
		panel_4.add(cp_job_type, gbc_cp_job_type);
		cp_job_type.setColumns(10);
		
		JLabel label = new JLabel("사원수");
		GridBagConstraints gbc_label = new GridBagConstraints();
		gbc_label.anchor = GridBagConstraints.EAST;
		gbc_label.insets = new Insets(0, 0, 5, 5);
		gbc_label.gridx = 1;
		gbc_label.gridy = 8;
		panel_4.add(label, gbc_label);
		
		final JTextField cp_scale = new JTextField();
		cp_scale.setText("");
		GridBagConstraints gbc_cp_scale = new GridBagConstraints();
		gbc_cp_scale.insets = new Insets(0, 0, 5, 5);
		gbc_cp_scale.fill = GridBagConstraints.HORIZONTAL;
		gbc_cp_scale.gridx = 2;
		gbc_cp_scale.gridy = 8;
		panel_4.add(cp_scale, gbc_cp_scale);
		cp_scale.setColumns(10);
		
		JLabel label_1 = new JLabel("사업개요");
		GridBagConstraints gbc_label_1 = new GridBagConstraints();
		gbc_label_1.insets = new Insets(0, 0, 5, 5);
		gbc_label_1.gridx = 1;
		gbc_label_1.gridy = 9;
		panel_4.add(label_1, gbc_label_1);
		
		final JTextArea cp_content = new JTextArea();
		cp_content.setRows(10);
		cp_content.setText("");
		GridBagConstraints gbc_cp_content = new GridBagConstraints();
		gbc_cp_content.insets = new Insets(0, 0, 5, 5);
		gbc_cp_content.fill = GridBagConstraints.BOTH;
		gbc_cp_content.gridx = 2;
		gbc_cp_content.gridy = 9;
		panel_4.add(cp_content, gbc_cp_content);
		
		JLabel lblNewLabel_8 = new JLabel("설립일");
		GridBagConstraints gbc_lblNewLabel_8 = new GridBagConstraints();
		gbc_lblNewLabel_8.anchor = GridBagConstraints.EAST;
		gbc_lblNewLabel_8.insets = new Insets(0, 0, 5, 5);
		gbc_lblNewLabel_8.gridx = 1;
		gbc_lblNewLabel_8.gridy = 10;
		panel_4.add(lblNewLabel_8, gbc_lblNewLabel_8);
		
		final JTextField cp_incor_day = new JTextField();
		GridBagConstraints gbc_cp_incor_day = new GridBagConstraints();
		gbc_cp_incor_day.insets = new Insets(0, 0, 5, 5);
		gbc_cp_incor_day.fill = GridBagConstraints.HORIZONTAL;
		gbc_cp_incor_day.gridx = 2;
		gbc_cp_incor_day.gridy = 10;
		panel_4.add(cp_incor_day, gbc_cp_incor_day);
		cp_incor_day.setColumns(10);
		
		JPanel panel = new JPanel();
		add(panel, BorderLayout.SOUTH);
		
		JButton create = new JButton("작성완료");
		panel.add(create);
		JButton update = new JButton("다시작성");
		panel.add(update);
		
		update.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				cp_reg_no.setText("");
				cp_name.setText("");
				cp_pre.setText("");
				cp_addr.setText("");
				cp_phone.setText("");
				cp_job_type.setText("");
				cp_scale.setText("");
				cp_content.setText("");
				cp_incor_day.setText("");
			}
		});
		create.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) 
			{
				//등록버튼액션
			
				cv.setMb_no(mb_no);
			
				cv.setCp_reg_no(cp_reg_no.getText());
				
				cv.setCp_name(cp_name.getText());
				
				cv.setCp_pre(cp_pre.getText());
				cv.setCp_addr(cp_addr.getText());
				cv.setCp_phone(cp_phone.getText());
				cv.setCp_job_type(cp_job_type.getText());
				cv.setCp_scale(cp_scale.getText());
				cv.setCp_content(cp_content.getText());
				cv.setCp_incor_day(cp_incor_day.getText());
				
			
				if(cdao.InsertCompany(cv)){
					System.out.println("등록 되었습니다");}
				else System.out.println("등록실패 하였습니다");
				
				
			}
			
			
		});
		
		
		setVisible(true);

	}

}
